#include "ButtonListItem.h"

ButtonListItem::ButtonListItem(std::string keyValue, std::string path, bool selected, int posX, int posY,
		Widget *parent) :
		WidgetClickeableWithTextAligned(" ",path,posX, posY, parent) {
	this->pressed = selected;
	this->keyValue = keyValue;
}
ButtonListItem::ButtonListItem(std::string buttonName, Color color, bool selected, int w, int h,int posX, int posY,
		Widget *parent) :
		WidgetClickeableWithTextAligned(buttonName,color,w,h,posX, posY, parent) {
	this->pressed = selected;
	this->keyValue = buttonName;
}


void ButtonListItem::handleEvent(Event event, Parcel* parentParcel) {
	if (!isMouseOver(event, parentParcel))
		return;


	if ((event.getType()) == MouseButtonPressed) {
		this->pressed = true;
		Logger::log("Button", "handleEvent", "MOUSEBUTTONDOWN");
	} else if ((event.getType()) == MouseButtonReleased) {
		this->pressed = false;
		Logger::log("Button", "handleEvent", "SDL_MOUSEBUTTONUP");
	}

	WidgetClickeableWithTextAligned::handleEvent(event);
}

void ButtonListItem::setPressed(bool pressed){
	this->pressed = pressed;
}

bool ButtonListItem::isMouseOver(Event event, Parcel* parentParcel) const {
	return ((event.getXCoordinate() > this->parcel->posX + parentParcel->posX)
			&& (event.getXCoordinate() < this->parcel->posX + this->parcel->width + parentParcel->posX)
			&& (event.getYCoordinate() > this->parcel->posY + parentParcel->posY)
			&& (event.getYCoordinate() < this->parcel->posY
					+ this->parcel->height + parentParcel->posY));
}

std::string ButtonListItem::getKeyValue() const
{
    return keyValue;
}

